﻿namespace Micro.Extensions.Cache
{
    public class CacheValue<T>
    {
        public CacheValue(T value, bool hasValue = true)
        {
            Value = value;
            HasValue = hasValue;
        }

        /// <summary>
        /// 是否有缓存值
        /// </summary>
        public bool HasValue { get; }

        /// <summary>
        /// 缓存值
        /// </summary>
        public T Value { get; }

        /// <summary>
        /// 缓存值是否为Null
        /// </summary>
        public bool IsNull => Value == null;

        /// <summary>
        /// 获取null值缓存
        /// </summary>
        public static CacheValue<T> NoValue { get; } = new CacheValue<T>(default, false);

        public override string ToString()
        {
            return Value?.ToString() ?? "";
        }
    }
}
